import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Employee implements Serializable {

	/**
	 * Clase serializable
	 */
	private static final long serialVersionUID = 7L;
	/**
	 * Atributos
	 */
	private String lastname; // No debe de pasar de 20 caracteres de longitud
	private String name; // No debe de pasar de 20 caracteres de longitud
	private int job; // (Foreign Key Table JOB)
	private int id;
	private Date regis_date; // dd/mm/yy
	private double Salary;
	private double Commission;
	private int Dept_Number; // Foreign Key Table DEPARMENT

	// Atributos creados por mi
	/*
	 * private String job2; private String deptnum2;
	 */

	public Employee(int id, String name, String lastname, int job,
			String regis_date, double salary, double commission, int dept_Number) {
		super();
		this.id = id;
		this.name = cortaName(name);
		this.lastname = cortaApellido(lastname);
		this.job = job;
		SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
		// formateo
		try {
			this.regis_date = formato.parse(regis_date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			this.regis_date = null;
		}
		this.Salary = salary;
		this.Commission = commission;
		this.Dept_Number = dept_Number;
	}

	/**
	 * @return the lastname
	 */
	public String getLastname() {
		return lastname;
	}

	/**
	 * @param lastname
	 *            the lastname to set
	 */
	public void setLastname(String lastname) {
		this.lastname = cortaApellido(lastname);
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = cortaName(name);
	}

	/**
	 * @return the job
	 */
	public int getJob() {
		return job;
	}

	/**
	 * @param job
	 *            the job to set
	 */
	public void setJob(int job) {
		this.job = job;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the regis_date
	 */
	public Date getRegis_date() {
		return regis_date;
	}

	/**
	 * @param regis_date
	 *            the regis_date to set
	 */
	public void setRegis_date(Date regis_date) {
		this.regis_date = regis_date;
	}

	/**
	 * @return the salary
	 */
	public double getSalary() {
		return Salary;
	}

	/**
	 * @param salary
	 *            the salary to set
	 */
	public void setSalary(double salary) {
		Salary = salary;
	}

	/**
	 * @return the commission
	 */
	public double getCommission() {
		return Commission;
	}

	/**
	 * @param commission
	 *            the commission to set
	 */
	public void setCommission(double commission) {
		Commission = commission;
	}

	/**
	 * @return the dept_Number
	 */
	public int getDept_Number() {
		return Dept_Number;
	}

	/**
	 * @param dept_Number
	 *            the dept_Number to set
	 */
	public void setDept_Number(int dept_Number) {
		Dept_Number = dept_Number;
	}

	/**
	 * Ajusta el nombre a un maximo de 20 chars
	 * 
	 * @return
	 */
	public String cortaName(String name) {
		int tam = 20;
		if (name.length() > 20) {
			this.name = name.substring(0, tam);
		} else {
			// No hacer nada
		}
		return name;
	}

	/**
	 * Ajusta el apellido a un maximo de 20 chars
	 * 
	 * @return
	 */
	public String cortaApellido(String lastname) {
		int tam = 20;
		if (lastname.length() > 20) {
			this.lastname = lastname.substring(0, tam);
		} else {
			// No hacer nada
		}
		return lastname;
	}

	/**
	 * Metodo que cambia el String del archivo fecha a un tipo Date formateado
	 * (dd/mm/yy)
	 */
	public void formatDate(String fecha) {
		SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
		// formateo
		try {
			this.regis_date = formato.parse(fecha);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public String toString() {
		return "ID: "+id + "\nName: " + name + "\nLast Name: " + lastname + "\nRegistration Date: " + regis_date+"\nSalary: "
				+ Salary + "\nCommission: " + Commission + " ";
	}
	/*
	 * @Override public String toString(){ return
	 * id+" "+name+" "+lastname+" "+job
	 * +" "+regis_date+" "+" "+Salary+" "+Commission+" "+Dept_Number; }
	 */

}
